package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingLevelController
 * @Author loe
 * @Date 2024-07-09
 */

@RestController
@Api(tags = "护理等级相关接口")
@RequestMapping("/nursingLevel")
public class NursingLevelController extends BaseController{

    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 查询所有护理等级
     * @return ResponseResult<List<NursingLevelVo>>
     */
    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> searchAll() {
        List<NursingLevelVo> nursingLevelVoList = nursingLevelService.searchAll();
        return success(nursingLevelVoList);
    }

    /**
     * 新增
     * @param nursingLevelDto
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation(value = "新增")
    public ResponseResult insert(
            @RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.insert(nursingLevelDto);
        return success();
    }

    /**
     * 条件分页查询
     * @param pageNum 页码（默认为1）
     * @param pageSize 每页大小（默认为10）
     * @param name 护理等级名称
     * @param status 护理等级状态
     * @return
     */
    @GetMapping("/listByPage")
    @ApiOperation(value = "条件分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>> limitSearch(
            @ApiParam(value = "页码（默认为1）") Integer pageNum,
            @ApiParam(value = "每页大小（默认为10）") Integer pageSize,
            @ApiParam(value = "护理等级名称") String name,
            @ApiParam(value = "护理等级状态") Integer status
    ) {
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.limitSearch(pageNum, pageSize, name, status);
        return success(pageResponse);
    }

    /**
     * 根据id查询
     * @param id 护理等级ID
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询")
    public ResponseResult<NursingLevelVo> getById(
            @ApiParam(value = "护理等级ID") @PathVariable Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return success(nursingLevelVo);
    }

    /**
     * 修改
     * @param nursingLevelDto
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.update(nursingLevelDto);
        return success();
    }

    /**
     * 删除
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除")
    public ResponseResult delete(
            @ApiParam(value = "护理等级ID") @PathVariable Long id) {
        nursingLevelService.delete(id);
        return success();
    }

    /**
     * 启用禁用
     * @param id 护理等级ID
     * @param status 状态，0：禁用，1：启用
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    public ResponseResult setStatus(
            @ApiParam(value = "护理等级ID") @PathVariable Long id,
            @ApiParam(value = "状态，0：禁用，1：启用") @PathVariable Integer status
    ) {
        nursingLevelService.setStatus(id, status);
        return success();
    }
}
